package com.cn.demo4.dao.impl;

import com.cn.demo4.dao.HouseDao;
import com.cn.demo4.model.HouseModel;
import com.cn.demo4.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class HouseDaoImpl implements HouseDao {
    @Override
    public List<HouseModel> findAll() {
        String sql="select * from house where is_show=1";
        List<HouseModel> list = new ArrayList<>();
        ResultSet resultSet = JDBC.select(sql);
        try{
            while(resultSet.next()){
                HouseModel houseModel = new HouseModel();
                houseModel.setId(resultSet.getInt("id"));
                houseModel.setName(resultSet.getString("name"));
                list.add(houseModel);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
